package morning.cat.springboot.demo.controller;

import morning.cat.springboot.demo.config.EventPublisher;
import morning.cat.springboot.demo.config.EventPublisherTwo;
import morning.cat.springboot.demo.event.HelloApplicationEvent;
import morning.cat.springboot.demo.event.WorldApplicationEvent;
import morning.cat.springboot.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @describe: 类描述信息
 * @author: morningcat.zhang
 * @date: 2019/3/4 2:06 PM
 */
@RestController
@RequestMapping("/")
public class HelloController {

    @Autowired
    private EventPublisher eventPublisher;


    @Autowired
    private EventPublisherTwo eventPublisherTwo;

    @GetMapping("/hello1")
    public String hello1() {
        HelloApplicationEvent event = new HelloApplicationEvent(this, "Hello");
        eventPublisher.publishEvent(event);
        return "Hello";
    }

    @GetMapping("/hello2")
    public String hello2() {
        User user = new User().setId(1L).setName("gouzi");
        WorldApplicationEvent event = new WorldApplicationEvent(this, user);
        eventPublisher.publishEvent(event);
        return "Hello";
    }

    @GetMapping("/hello3")
    public String hello3() {
        HelloApplicationEvent event = new HelloApplicationEvent(this, "eventPublisherTwo");
        eventPublisherTwo.publishEvent(event);
        return "eventPublisherTwo";
    }
}
